package com.nongye.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nongye.common.annotation.Log;
import com.nongye.common.core.controller.BaseController;
import com.nongye.common.core.domain.AjaxResult;
import com.nongye.common.enums.BusinessType;
import com.nongye.system.domain.NyDict;
import com.nongye.system.service.INyDictService;
import com.nongye.common.utils.poi.ExcelUtil;
import com.nongye.common.core.page.TableDataInfo;

/**
 * 农产品字典Controller
 * 
 * @author nongye
 * @date 2023-09-19
 */
@Api(value = "农产品字典管理",tags = "农产品字典管理")
@RestController
@RequestMapping("/system/nydict")
public class NyDictController extends BaseController
{
    @Autowired
    private INyDictService nyDictService;

    /**
     * 查询农产品字典列表
     */
    @ApiOperation(value = "查询农产品字典列表")
   // @PreAuthorize("@ss.hasPermi('system:dict:list')")
    @GetMapping("/list")
    public TableDataInfo list(NyDict nyDict)
    {
        startPage();
        List<NyDict> list = nyDictService.selectNyDictList(nyDict);
        return getDataTable(list);
    }

    /**
     * 导出农产品字典列表
     */
    @ApiOperation(value = "导出农产品字典列表")
   // @PreAuthorize("@ss.hasPermi('system:dict:export')")
    @Log(title = "农产品字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NyDict nyDict)
    {
        List<NyDict> list = nyDictService.selectNyDictList(nyDict);
        ExcelUtil<NyDict> util = new ExcelUtil<NyDict>(NyDict.class);
        util.exportExcel(response, list, "农产品字典数据");
    }

    /**
     * 获取农产品字典详细信息
     */
    @ApiOperation(value = "获取农产品字典详细信息")
//    @PreAuthorize("@ss.hasPermi('system:dict:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nyDictService.selectNyDictById(id));
    }

    /**
     * 新增农产品字典
     */
    @ApiOperation(value = "新增农产品字典")
//    @PreAuthorize("@ss.hasPermi('system:dict:add')")
    @Log(title = "农产品字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NyDict nyDict)
    {
        return toAjax(nyDictService.insertNyDict(nyDict));
    }

    /**
     * 修改农产品字典
     */
    @ApiOperation(value = "修改农产品字典")
//    @PreAuthorize("@ss.hasPermi('system:dict:edit')")
    @Log(title = "农产品字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NyDict nyDict)
    {
        return toAjax(nyDictService.updateNyDict(nyDict));
    }

    /**
     * 删除农产品字典
     */
    @ApiOperation(value = "删除农产品字典")
//    @PreAuthorize("@ss.hasPermi('system:dict:remove')")
    @Log(title = "农产品字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nyDictService.deleteNyDictByIds(ids));
    }
}
